package shiyan5;

import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;


class PersonSortable2 implements Comparator<PersonSortable2>{
	private String name;
	private int age;
	public PersonSortable2(String name,int age) {
		this.setName(name);
		this.setAge(age);
	}
	@Override
	public String toString() {
		return getName()+'-'+getAge();
	}
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public int getAge() {
		return age;
	}
	public void setAge(int age) {
		this.age = age;
	}
	@Override
	public int compare(PersonSortable2 o1, PersonSortable2 o2) {
		// TODO Auto-generated method stub
		return 0;
	}
}
class NameComparator implements Comparator<PersonSortable2>{

	@Override
	public int compare(PersonSortable2 o1, PersonSortable2 o2) {
		if(o1.getName().compareTo(o2.getName())>0){
			return 1;
		}
		else if(o1.getName().compareTo(o2.getName())<0){
			return -1;
		}
		return 0;
	}
	
}
class AgeComparator implements Comparator<PersonSortable2>{

	@Override
	public int compare(PersonSortable2 o1, PersonSortable2 o2) {
		if(o1.getAge()>o2.getAge()){
			return 1;
		}
		else if(o1.getAge()<o2.getAge()){
			return -1;
		}
		return 0;
	}
	
}
public class Sy52 {

	public static void main(String[] args) {
		Scanner input=new Scanner(System.in);
		int n=input.nextInt();
		PersonSortable2 person[]=new PersonSortable2[n];
		for(int i=0;i<n;i++){
			person[i]=new PersonSortable2(input.next(),input.nextInt());
		}
		System.out.println("NameComparator:sort");
		NameComparator NameComparator=new NameComparator();
		Arrays.sort(person,NameComparator);
		for (PersonSortable2 e : person) {
			System.out.println(e);
		}
		System.out.println("AgeComparator:sort");
		AgeComparator AgeComparator=new AgeComparator();
		Arrays.sort(person,AgeComparator);
		for (PersonSortable2 e : person) {
			System.out.println(e);
		}
		System.out.println(Arrays.toString(NameComparator.class.getInterfaces()));
		System.out.println(Arrays.toString(AgeComparator.class.getInterfaces()));

	}
}

